package stream;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;

public class fromcollection {
    public static void main(String[] args) throws Exception {
    //    创建流式执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    //    创建list
        ArrayList<Integer> data = new ArrayList<Integer>();
        data.add(10);
        data.add(20);
        data.add(30);
        data.add(40);
        data.add(50);
    //    创建数据源
        DataStreamSource<Integer> source =  env.fromCollection(data);

    //    map
        DataStream<Integer> result = source.map(new MapFunction<Integer, Integer>() {
            public Integer map(Integer value) throws Exception {
                return value + 1;
            }
        });

        result.print().setParallelism(2);

        env.execute("fromcollection");
    }
}
